﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DefWinMsgTest
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public Form1()
        {
            InitializeComponent();
        }

        protected override void DefWndProc(ref Message m)
        {
            if (m.Msg == 222)
            {
                ultraButton2.Visible = !ultraButton2.Visible;
            }else if (m.Msg == 111)
            {
                ultraButton1.Visible = !ultraButton1.Visible;
            }
            else
            {
                base.DefWndProc(ref m);
            }
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {

            SendMessage(this.Handle, 222, 1, 0);
        }

        private void ultraButton2_Click(object sender, EventArgs e)
        {
            SendMessage(this.Handle, 111, 1, 0);
        }

        private Form2 form2;
        private void Form1_Load(object sender, EventArgs e)
        {
            form2 = new Form2();
            form2.Show();
        }

        private void ultraButton3_Click(object sender, EventArgs e)
        {
            SendMessage(form2.Handle, 333, 1, 0);
        }
    }
}
